<script>
export default {
  name: "Aside.vue",
  props: {
    isCollapse: Boolean,
    hasLogoTextShow: Boolean,
  },
  data(){
    return{
      menuList: localStorage.getItem("menuList")? JSON.parse(localStorage.getItem("menuList")):[],
      opens:localStorage.getItem("menuList")? JSON.parse(localStorage.getItem("menuList")).map(menu=>menu.menuId):[],
      isLogo: localStorage.getItem('configuration')?JSON.parse(localStorage.getItem('configuration')).isLogo:this.$store.state.configuration.isLogo,
    }

  },
  methods:{
    addTab(item){
      this.$store.commit("selectMenu",item);
    }
  }
}
</script>

<template>
  <el-menu :default-openeds="opens"
           style="min-height: 100%;overflow-x: hidden;overflow-y: hidden;box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35)"
           background-color="#5b6c6c"
           text-color="#fff"
           active-text-color="rgb(235, 181, 99)"
           :collapse-transition="false"
           :unique-opened="true"
           :collapse="isCollapse"
           router
  >
    <div style="height:60px;line-height:60px;text-align:center;background-color: #303838" v-if="isLogo">
      <img src="../assets/logo6.png" alt="" style="width:25px;position:relative;top:7px;margin-right:3px"/>
      <b style="color:white" v-show="hasLogoTextShow">问诊挂号系统</b>
    </div>
    <div v-for="item in menuList" :key="item.menuId">
      <div v-if="item.path">
        <el-menu-item :index="item.path" @click="addTab(item)">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.menuName }}</span>
        </el-menu-item>
      </div>
      <div v-else>
        <el-submenu :index="item.menuId+''">
          <template slot="title">
            <i :class="item.icon"></i>
            <span slot="title">{{item.menuName}}</span>
          </template>
          <div v-for="subItem in item.submenuList" :key="subItem.menuId">
            <div v-if="subItem.path">
              <el-menu-item :index="subItem.path" @click="addTab(subItem)">
                <i :class="subItem.icon"></i>
                <span slot="title">{{subItem.menuName}}</span>
              </el-menu-item>
            </div>
           <div v-else>
             <el-submenu :index="subItem.menuId+''">
             <template slot="title">
               <i :class="subItem.icon"></i>
               <span slot="title">{{subItem.menuName}}</span>
             </template>
               <div v-for="thirdItem in subItem.submenuList" :key="thirdItem.menuId">
                 <el-menu-item :index="thirdItem.path" @click="addTab(thirdItem)">
                   <i :class="thirdItem.icon"></i>
                   <span slot="title">{{thirdItem.menuName}}</span>
                 </el-menu-item>
               </div>
             </el-submenu>
           </div>
          </div>
        </el-submenu>
      </div>
    </div>
  </el-menu>
</template>

<style scoped>
.el-menu-item.is-active {
  background-color: rgb(157, 185, 185) !important;
}

.el-menu-item:hover {
  background-color: rgb(157, 185, 185) !important;
}

.el-submenu__title:hover {
  background-color: rgb(157, 185, 185) !important;
}

/*解决收缩菜单文字不消失问题*/
.el-menu--collapse span {
  visibility: hidden;
}
</style>
